package com.yl.chainStore.services


import com.alibaba.fastjson.JSONObject
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.entity.customer.*
import com.yl.chainStore.entity.pay.*
import com.yl.chainStore.entity.sick.*
import com.yl.chainStore.entity.warehouse.TechnologyProcessing
import com.yl.chainStore.pojo.vo.customer.CustomerInfoAssociatedUpdateVo
import com.yl.chainStore.pojo.vo.customer.CustomerLeftJoinInfo
import com.yl.chainStore.pojo.vo.pay.*
import com.yl.chainStore.pojo.vo.sick.*
import com.yl.chainStore.pojo.vo.warehouse.TechnologyProcessingMapperVo
import com.yl.users.entity.CompanyUser
import java.util.*
import com.yl.common.control.ResponseBody as ResponseBody

/**
 * 客户信息操作
 */
interface ICustomerInfoService {

    /**
     * 单个详情
     */
    fun getById(id: Long): CustomerInfo?

    /**
     * 列表查询时，关联患者的信息   患者也会直接加进去
     * 1，患者基本信息
     * 2，患者项目显示信息
     * 3，患者是否欠款
     */
    fun getJoinInfoByCustomerId(id: Long, joinInfo: CustomerLeftJoinInfo): CustomerInfo?

    /**
     * 修改
     */
    fun update(customerInfo: CustomerInfo): ResponseBody

    /**
     * 修改来源（主要是要清除之前的来源）
     * 例如 内部来源要改外部来源   则内部来源的要设置为null，
     */
    fun updateSource(customerInfo: CustomerInfo): ResponseBody

    /**
     * 设置手机号码
     */
    fun setMobile(customerId: Long, phoneList: List<CustomerInfoPhone>): ResponseBody

    /**
     * 获取手机
     */
    fun getMobile(customerInfo: CustomerInfo): ResponseBody

    /**
     * 获取手机显示方式
     */
    fun getMobileStr(customerInfo: CustomerInfo): ResponseBody

    /**
     * 显示一个手机
     */
    fun getMobileFirstStr(customerInfo: CustomerInfo): ResponseBody

    /**
     * 设置电话号码
     */
    fun setPhone(customerId: Long, phoneList: List<CustomerInfoPhone>): ResponseBody

    /**
     * 获取电话
     */
    fun getPhone(customerInfo: CustomerInfo): ResponseBody

    /**
     * 获取电话显示方式
     */
    fun getPhoneStr(customerInfo: CustomerInfo): ResponseBody

    /**
     * 获取患者手机和电话（直接设置到customerInfo 的属性里面去）
     */
    fun getMobileAndPhone(customerInfo: CustomerInfo): ResponseBody

    /**
     * 患者推荐人数量
     */
    fun getRecommendedCustomerCount(customerId: Long): Int

    /**
     * 患者推荐人列表
     */
    fun getRecommendedCustomerList(customerId: Long): List<CustomerInfo>

    /**
     * 添加患者关系人
     */
    fun addAssociatedCustomer(associate: CustomerInfoAssociated): ResponseBody

    /**
     * 删除关系
     */
    fun delAssociatedCustomer(associateId: Long): ResponseBody

    /**
     * 修改关系（不支持换人）
     */
    fun updateCustomerAssociated(associate: CustomerInfoAssociatedUpdateVo): ResponseBody

    /**
     * 获取关系人列表
     */
    fun getAssociatedList(customerId: Long): List<CustomerInfoAssociated>

    /**
     * 挂号(如果选记了就诊记录就用修改就诊录状态，没有的话就创建就诊记录，并处理订单)
     */
    fun registered(vo: CustomerRegisteredVo): ResponseBody

    /**
     * 获取客户当日预约的就诊记录（未处理的）
     */
    fun getTodayWaitingRecordDetail(customerId: Long): SickMedicalRecordsDetail?

    /**
     * 添加一个就诊明细
     */
    fun addMedicalRecordDetail(detail: SickMedicalRecordsDetail): ResponseBody

    /**
     * 创建一个就诊记录
     */
    fun createMedicalRecords(record: SickMedicalRecords): ResponseBody

    /**
     * 创建一个空白的订单（不包含明细）
     */
    fun createOrder(
        order: PayCustomerOrder
    ): ResponseBody


    /**
     * 查询病人所有的订单分页
     */
    fun getOrderPage(

        vo: PayCustomerOrderSelectVo
    ): Page<PayCustomerOrder>

    /**
     * 查询病人所有订单的列表
     */
    fun getOrderList(
        vo: PayCustomerOrderSelectVo
    ): List<PayCustomerOrder>

    /**
     * 余额变动记录
     */
    fun getCustomerMoneyFlowList(vo: PayCustomerMoneyFlowSelectVo): List<PayCustomerMoneyFlow>

    /**
     * 关联查询余额变动记录
     */
    fun getCustomerMoneyFlowByAssociateId(associateId:Long,typeEnum: TypeEnum): List<PayCustomerMoneyFlow>

    /**
     * 关联查询余额变现记录
     */
    fun getBalanceToMoneyLogBYAssociateId(associateId:Long,useType: TypeEnum):List<PayCustomerBalanceToMoneyLog>

    /**
     * 查询正在进行中的就诊记录
     */
    fun getOnGoingRecord(customerId: Long): List<SickMedicalRecords>

    /**
     * 查询病人就诊记录分页
     */
    fun getRecordPage(
        page: Page<SickMedicalRecords>,
        vo: SickMedicalRecordsSelectVo
    ): Page<SickMedicalRecords>

    /**
     * 查询病人就诊记录分页
     */
    fun getRecordList(
        vo: SickMedicalRecordsSelectVo
    ): List<SickMedicalRecords>


    /**
     * 创建计划
     */
    fun createAccessLog(accessLog: SickCustomerAccessLog): ResponseBody

    /**
     * 通过随访计划创建随访
     */
    fun createAccessLogByPlanDetail(plan: SickCustomerAccessLogPlan,standardTime:Date,detail: SickCustomerAccessLogPlanDetail): ResponseBody

    /**
     * 获取下一次随访计划
     */
    fun getNextAccessLogByPlanDetail(detail: SickCustomerAccessLogPlanDetail):SickCustomerAccessLogPlanDetail?


    /**
     * 回访分页记录
     */
    fun getAccessLogPage(
        page: Page<SickCustomerAccessLog>,
        vo: SickCustomerAccessLogSelectVo
    ): Page<SickCustomerAccessLog>

    /**
     * 获取随访，回访
     */
    fun getAccessLogList(
        vo: SickCustomerAccessLogSelectVo
    ): List<SickCustomerAccessLog>

    /**
     * 获取最后一次随访
     */
    fun getLastCompleteAccessLog(customerId: Long, accessType: TypeEnum): SickCustomerAccessLog?

    /**
     * 获取用户账户信息
     */
    fun getCustomerAccount(customerId: Long,subCompanyId: Long): PayCustomerAccount

    /**
     * 充值余额
     * @param customerId 患者
     * @param money      金额
     * @param payType    付款类型   641-700 支付方式
     * @param remark    备注
     * @param useType   余额变动类型（余额变动记录）  481-550 用户余额变动类型
     * @param associatedTopId 关联id   如果是订单付款，则为付款记录的id  pay_order_customer_pay_log_detail 的id 因为是以明晰为基础的一次充值
     * @param payTime 付款时间
     */
    fun topUpBalance(
        customerId: Long,
        money: Long,
        payType: TypeEnum,
        useType: TypeEnum,
        remark: String?,
        giftsOfGold: Long?,
        associatedTopId: Long?,
        payTime: Date?
    ): ResponseBody


    /**
     * 添加余额(不添加充值记录)
     * @param customerId 患者
     * @param money      金额
     * @param remark    备注
     * @param useType   充值类型（余额变动记录）  481-550 用户余额变动类型
     * @param associatedId 关联id
     */
    fun onlyAddBalance(customerId: Long,
                       money: Long,
                       useType: TypeEnum,
                       remark: String?,
                       associatedId:Long?): ResponseBody

    /**
     * 余额添加（不做任何记录）
     */
    fun onlyTopBalance(customerId: Long,money: Long):ResponseBody

    /**
     * 余额扣除（不做任何记录）
     */
    fun onlySubBalance(customerId: Long,money: Long):ResponseBody

    /**
     * 添加馈赠金（不做记录）
     */
    fun onlyAddGiftsOfGold(customerId: Long,money: Long):ResponseBody

    /**
     * 扣除馈赠金，不做记录
     */
    fun onlySubiftsOfGold(customerId: Long,money: Long):ResponseBody

    /**
     * 扣除馈赠金(使用)
     *
     */
    fun subGiftsOfGold(
        customerId: Long,
        associateId: Long?,
        money: Long,
        updateType: TypeEnum,
        remark: String?
    ): ResponseBody

    /**
     * 余额转现金
     */
    fun balanceToMoney(
        customerId: Long,
        money: Long,
        useType: TypeEnum,
        payType: TypeEnum,
        remark: String?,
        giftsOfGold: Long?,
        associateId: Long?
    ): ResponseBody

    /**
     * 转账
     */
    fun balanceToOtherCustomer(
        customerId: Long,
        toCustomerId: Long,
        money: Long,
        remark: String?,
        giftsOfGold: Long?
    ): ResponseBody

    /**
     * 添加积分
     */
    fun topUpIntegral(customerId: Long, integral: Long, remark: String?): ResponseBody

    /**
     * 添加欠款
     */
    fun addAmountOwed(customerId: Long, amountOwed: Long, remark: String?): ResponseBody

    /**
     * 扣除欠款
     */
    fun subAmountOwed(customerId: Long, amountOwed: Long, remark: String?): ResponseBody



    /**
     * 获取客户订单总价(已经下单之后的)
     */
    fun getCustomerOrderSumMoney(customerId: Long,subCompanyId: Long?): Long

    /**
     * 获取客户订单总价(已经下单之后的)
     */
    fun getCustomerOrderAmountSumMoney(customerId: Long,subCompanyId: Long?): Long

    /**
     * 获取用户消费总价
     */
    fun getCustomerPaySumMoney(customerId: Long,subCompanyId: Long?): Long

    /**
     * 获取用户优惠卷
     */
    fun getCustomerCouponsList(vo: PayCustomerCouponsSelectVo): List<PayCustomerCoupons>

    /**
     * 发放优惠卷给客户
     */
    fun addCouponsToCustomer(couponsId: Long, customerId: Long, count: Int): ResponseBody

    /**
     * 添加一个预约
     */
    fun addSubscribeLog(subscribeLog: CustomerSubscribeLog): ResponseBody

    /**
     * 重设最后就诊记录id
     */
    fun refreshLastRecordsDetailId(customerId: Long): ResponseBody

    /**
     * 最后一次的就诊记录明细
     */
    fun getLastRecordsDetail(customerId: Long): SickMedicalRecordsDetail?

    /**
     * 就诊记录明细列表
     */
    fun getCustomerRecordsDetailList(vo: SickMedicalRecordsDetailSelectVo): List<SickMedicalRecordsDetail>

    /**
     * 就诊记录明细分页
     */
    fun getCustomerRecordsDetailPage(
        page: Page<SickMedicalRecordsDetail>,
        vo: SickMedicalRecordsDetailSelectVo
    ): Page<SickMedicalRecordsDetail>

    /**
     * 患者预约记录
     */
    fun getCustomerSubscribeLogPage(vo: CustomerSubscribeLogSelectVo): Page<CustomerSubscribeLog>

    /**
     * 获取当日预约信息
     */
    fun getToDayCustomerSubscribeLog(customerId: Long, subCompanyId: Long): CustomerSubscribeLog?

    /**
     * 当日没有就诊信息的预约
     */
    fun getCustomerToDayLogNotHaveRecord(customerId: Long, subCompanyId: Long): CustomerSubscribeLog?

    /**
     * 获取当天最近的一次预约（当天（包含当天）之后，）
     */
    fun getLatelySubscribeLog(customerId: Long, companyId: Long, subCompanyId: Long?): CustomerSubscribeLog?

    /**
     * 付款（出钱）
     * @return json payMoney  余额付款
     *              payGiftsOfGold 馈赠金付款
     *
     * associateId
     */
    fun pay(
        customerId: Long,
        money: Long,
        useType: TypeEnum,
        associateId: Long?,
        remark: String?,
        payTime:Date?
    ): ResponseBody

    /**
     * 关联的馈赠金变化
     */
    fun getGiftsOfGold(associateId:Long,updateType: TypeEnum):List<PayCustomerGiftsOfGold>

    /**
     * 添加病历
     */
    fun addMedicalHistory(medicalHistory: SickMedicalHistory): ResponseBody

    /**
     * 获取客户病历
     */
    fun getMedicalHistoryList(vo: SickMedicalHistorySelectVo): List<SickMedicalHistory>

    /**
     * 添加图片
     */
    fun addImage(image: SickCustomerImage): ResponseBody

    /**
     * 获取图片列表
     */
    fun getImageList(customerId: Long, vo: SickCustomerImageSelectVo): List<SickCustomerImage>

    /**
     * 删除图片
     */
    fun delImage(id:Long):ResponseBody

    /**
     * 获取客户服务项目列表
     */
    fun getOrderDetailList(customerId: Long, vo: PayCustomerOrderDetailSelectVo): List<PayCustomerOrderDetail>


    /**
     * 查询订单
     */
    fun getCustomOrderList(id: Long): List<PayCustomOrderProcessVo>

    /**
     * 获取最后一张订单
     */
    fun getCustomerLastOrder(customerId: Long, vo: PayCustomerOrderSelectVo): PayCustomerOrder?

    /**
     * 通过订单，添加回访信息
     */
    fun addVisitByOrder(customerId: Long, deptId: Long, order: PayCustomerOrder): ResponseBody

    /**
     * 通过订单，添加订单内项目流程
     */
    fun addOperatorLogByOrder(customerId: Long, deptId: Long, order: PayCustomerOrder): ResponseBody

    /**
     * 添加订单就诊记录
     */
    fun addOperatorLog(operatorLog: PayCustomerOrderItemOperatorLog): ResponseBody

    /**
     * 根据订单明细（开始时间） 获取要显示的规则
     */
    fun getShowRuleByOrderDetail(customerId: Long, subCompanyId: Long): List<PayItemCustomerShowRule>

    /**
     * 查询自己的技加工分页
     */
    fun getProcessingPage(vo: TechnologyProcessingMapperVo): Page<TechnologyProcessing>

    /**
     * 患者是否欠款
     * true 有欠款订单
     * false 没有欠款订单
     */
    fun customerHaveArrearsOrder(customerId: Long): Boolean


    // TODO: 2021/11/18 设置暂时放这边

    /**
     * 客户来源二级字典列表获取
     */
    fun getCustomerSecondSourceList(companyId: Long, parentValue: String?): List<CustomerInfoSecondSource>

    /**
     * 单个二级来源
     */
    fun getCustomerSecondSourceById(id: Long): CustomerInfoSecondSource?

    /**
     * 添加二级字典
     */
    fun addCustomerSecondSource(dist: CustomerInfoSecondSource): ResponseBody

    /**
     * 修改二级字典
     */
    fun updateCustomerSecondSource(dist: CustomerInfoSecondSource): ResponseBody

    /**
     * 删除二级字典
     */
    fun delCustomerSecondSource(id: Long): ResponseBody


    /**
     * 客户来源三级字典列表获取
     */
    fun getCustomerSourceDistList(companyId: Long, parentId: Long?): List<CustomerInfoSourceDist>

    /**
     * 添加字典
     */
    fun addCustomerSourceDist(dist: CustomerInfoSourceDist): ResponseBody

    /**
     * 修改字典
     */
    fun updateCustomerSourceDist(dist: CustomerInfoSourceDist): ResponseBody

    /**
     * 删除字典
     */
    fun delCustomerSourceDist(id: Long): ResponseBody

    /**
     * 添加对于订单付款记录（包含 余额支付）()
     * 注：一定要有明细才加
     *
     * */
    fun addPayOrderLog(payLog: PayOrderCustomerPayLog): ResponseBody

    /**
     * 返回指定用户发送通知消息的配置内容.
     * 如果为null.则指明不能使用发送
     */
    fun sendNoticeConfig(companyId: Long, customerId: Long, name: String): JSONObject?

    /**
     * 获取患者初诊医生
     */
    fun getCustomerFirstSickDoctor(customerId:Long):CompanyUser?

    /**
     * 获取患者就诊医生
     */
    fun getCustomerSickDoctor(customerId:Long):CompanyUser?

    /**
     * 获取患者责任医生
     */
    fun getCustomerResponsibilityDoctor(customerId:Long):CompanyUser?

    /**
     * 获取客户初诊咨询师
     */
    fun getCustomerFirstSickConsultant(customerId:Long):CompanyUser?

    /**
     * 获取客户就诊咨询师
     */
    fun getCustomerSickConsultant(customerId:Long):CompanyUser?

    /**
     * 获取客户所属咨询师
     */
    fun getCustomerConsultant(customerId:Long):CompanyUser?

    /**
     * 获取客户网电咨询师(暂时不用)
     */
    fun getCustomerNetConsultant(customerId:Long):CompanyUser?

    /**
     * 创建随访计划
     */
    fun createAccessPlan(plan:SickCustomerAccessLogPlan):ResponseBody




}
